package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.PspWarnInfoDao;
import com.fdb.efp.nls.service.domain.PspWarnInfo;
import com.fdb.efp.nls.service.facade.PspWarnInfoService;
import com.fdb.efp.nls.service.vo.PspWarnInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 贷后预警信息表				<p>
 * @author chenqm1
 * @date 2018-05-04
 */
@Service("pspWarnInfoService")
public class PspWarnInfoServiceImpl implements PspWarnInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PspWarnInfoServiceImpl.class);

	@Autowired
	private PspWarnInfoDao pspWarnInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertPspWarnInfo(PspWarnInfoVO inPspWarnInfoVo) {
		logger.debug("当前新增数据为:"+ inPspWarnInfoVo.toString());
		int num = 0;
		try {
			PspWarnInfo pspWarnInfo = new PspWarnInfo();
			beanCopy(inPspWarnInfoVo, pspWarnInfo);
			num = pspWarnInfoDao.insertPspWarnInfo(pspWarnInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PspWarnInfoVO inPspWarnInfoVo) {
		logger.debug("当前删除数据条件为:"+ inPspWarnInfoVo);
		int num = 0;
		try {
			PspWarnInfo pspWarnInfo = new PspWarnInfo();
			beanCopy(inPspWarnInfoVo, pspWarnInfo);
			num = pspWarnInfoDao.deleteByPk(pspWarnInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspWarnInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PspWarnInfoVO inPspWarnInfoVo) {
		logger.debug("当前修改数据为:"+ inPspWarnInfoVo.toString());
		int num = 0;
		try {
			PspWarnInfo pspWarnInfo = new PspWarnInfo();
			beanCopy(inPspWarnInfoVo, pspWarnInfo);
			num = pspWarnInfoDao.updateByPk(pspWarnInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspWarnInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PspWarnInfoVO queryByPk(PspWarnInfoVO inPspWarnInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inPspWarnInfoVo);
		try {
			PspWarnInfo queryPspWarnInfo = new PspWarnInfo();
			beanCopy(inPspWarnInfoVo, queryPspWarnInfo);
			PspWarnInfo queryRslPspWarnInfo = pspWarnInfoDao.queryByPk(queryPspWarnInfo);
			if (Objects.nonNull(queryRslPspWarnInfo)) {
				PspWarnInfoVO outPspWarnInfoVo = beanCopy(queryRslPspWarnInfo, new PspWarnInfoVO());
				logger.debug("当前查询结果为:"+ outPspWarnInfoVo.toString());
				return outPspWarnInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspWarnInfoVO> queryAllOwner(PspWarnInfoVO pspWarnInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		PspWarnInfo pspWarnInfo = beanCopy(pspWarnInfoVo, new PspWarnInfo());
		List<PspWarnInfoVO> list = null;
		try {
			List<PspWarnInfo> pspWarnInfos = pspWarnInfoDao.queryAllOwnerByPage(pspWarnInfo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspWarnInfos.size());
			pageSet(pspWarnInfos, pspWarnInfo);
			list = (List<PspWarnInfoVO>) beansCopy(pspWarnInfos, PspWarnInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspWarnInfoVO> queryAllCurrOrg(PspWarnInfoVO pspWarnInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		PspWarnInfo pspWarnInfo = beanCopy(pspWarnInfoVo, new PspWarnInfo());
		List<PspWarnInfo> pspWarnInfos = pspWarnInfoDao.queryAllCurrOrgByPage(pspWarnInfo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pspWarnInfos.size());
		List<PspWarnInfoVO> list = null;
		try {
			pageSet(pspWarnInfos, pspWarnInfo);
			list = (List<PspWarnInfoVO>) beansCopy(pspWarnInfos, PspWarnInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspWarnInfoVO> queryAllCurrDownOrg(PspWarnInfoVO pspWarnInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		PspWarnInfo pspWarnInfo = beanCopy(pspWarnInfoVo, new PspWarnInfo());
		List<PspWarnInfo> pspWarnInfos = pspWarnInfoDao.queryAllCurrDownOrgByPage(pspWarnInfo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pspWarnInfos.size());
		List<PspWarnInfoVO> list = null;
		try {
			pageSet(pspWarnInfos, pspWarnInfo);
			list = (List<PspWarnInfoVO>) beansCopy(pspWarnInfos, PspWarnInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public int insertBatchPspWarnInfo(List<PspWarnInfoVO> pspWarnInfoVos) {
		logger.debug("当前新增数据为:"+ pspWarnInfoVos.toString());
		int num = 0;
		try {
			List<PspWarnInfo> pspWarnInfos=new ArrayList<PspWarnInfo>();
			for(PspWarnInfoVO PspWarnInfoVo :pspWarnInfoVos) {
				PspWarnInfo PspWarnInfo =new PspWarnInfo();
				beanCopy(PspWarnInfoVo, PspWarnInfo);
				pspWarnInfos.add(PspWarnInfo);
			}
			num = pspWarnInfoDao.insertBatchPspWarnInfo(pspWarnInfos);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}
}
